@tool
extends Panel

#1. button | label 的简单使用,以及事件的绑定
#2. 学会如何加载与实例化子场景 PackedScene
#3. 编辑器警告的产生 @tool 和 _get_configuration_warnings

var accum = 0
@export var Cat: PackedScene: # =  preload("res://pannel/cat.tscn")
	set(cat):
		if cat != Cat:
			Cat = cat
			update_configuration_warnings()

func _get_configuration_warnings():
	var warnings = []
	if Cat == null:
		warnings.append("Please set `Cat` to a non-empty value.")
	return warnings

# Called when the node enters the scene tree for the first time.
func _ready():
	# 手动事件绑定
	#get_node("Button").connect("pressed", Callable(self, "_on_Button_pressed"))
	#get_node("CreateCat").connect("pressed", Callable(self, "_on_create_cat_pressed"))
	pass

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	accum += delta
	#get_node("Label").text = str(accum) # 'text' is a built-in label property.

func add_a_cat():
	var new_ball = Cat.instantiate()
	var pos = get_viewport().get_mouse_position()
	new_ball.position = pos
	add_child(new_ball)
	print(pos)

func _on_Button_pressed():
	get_node("Label").text = "HELLO!"
	get_tree().call_group("enemies", "player_was_discovered")
	var enemies = get_tree().get_nodes_in_group("enemies")
	print(enemies)

func _on_create_cat_pressed():
	add_a_cat()

func _on_button_pressed():
	get_node("Label").text = "you really click! 运行时间:" +  str(int(accum))
